package jwdt.xadmin.system.action;

import jwdt.common.action.BaseAction;
import jwdt.common.util.CacheUtil;
import jwdt.xadmin.system.bean.QXJS;
import jwdt.xadmin.system.service.QXManageService;

import com.ezerg.db.Jdb;
import com.ezerg.db.ext.PageUtil;
import com.ezerg.web.Form;
import com.ezerg.web.Module;
import com.ezerg.web.Page;
import com.ezerg.web.annotation.Controller;
import com.ezerg.web.annotation.RequestMapping;

@Controller("/xadmin/system")
public class QxManagerAction extends BaseAction {
	
	private QXManageService qxManageService = (QXManageService)app.getBean("qxManageService");
	
	@RequestMapping("/listRole")
	public Page doListRole(Form f, Module m) throws Exception {
		PageUtil pu = (PageUtil)f.copy2Class(PageUtil.class);
    	return m.getWritePage(f, qxManageService.doList(pu).toJson());
	}
	
	@RequestMapping("/listJsForCombox")
	public Page doListJsForCombox(Form f, Module m) throws Exception {
		//生成json字符串
    	return m.getJsonPage(f, Jdb.get().query("select jsdm, jsmc from jwdt_qx_js ORDER BY jsdm asc", CacheUtil.C0));
	}
	
	@RequestMapping("/listJsForTree")
	public Page doListJsForTree(Form f, Module m) throws Exception {
		String oskey = f.getString("oskey");
		String flag = f.getString("flag");
    	return m.getWritePage(f, qxManageService.doListJsForTree(oskey, flag));
	}
	
	@RequestMapping("/addRole")
	public Page doAddact(Form f, Module m) throws Exception {
		QXJS obj = (QXJS)f.copy2Class(QXJS.class);
		return m.getWritePage(f, qxManageService.doAddact(obj));
	}
	
	@RequestMapping("/editRole")
	public Page doEditact(Form f, Module m) throws Exception {
		String jsdm = f.getString("jsdm");
		QXJS obj = (QXJS)f.copy2Class(QXJS.class);
		return m.getWritePage(f, qxManageService.doEditact(obj, jsdm));
	}
	
	@RequestMapping("/delRole")
	public Page doDel(Form f, Module m) throws Exception {
		String jsdm = f.getString("jsdm");
		return m.getWritePage(f, qxManageService.doDelact(jsdm));
	}
	
	@RequestMapping("/setRoleAct")
	public Page doSetRoleAct(Form f, Module m) throws Exception {
		String jsdm = f.getString("jsdm");
		String cddm = f.getString("cddm");
		String fldm = f.getString("fldm");
		String jscds = f.getString("jscd");
		String idss = f.getString("ids");
		return m.getWritePage(f, qxManageService.doSetRoleAct(jsdm, cddm, fldm, jscds, idss));
	}
	
	@RequestMapping("/roleWindow")
	public Page doLoad(Form f, Module m) throws Exception {
		String jsdm = f.getString("jsdm");
		f.add("obj", qxManageService.doLoad(jsdm));
		return m.findPage("/xadmin/system/roleWindow");
	}
	
	@RequestMapping("/setRoleWindow")
	public Page doAdminSetRoleWindowManage(Form f, Module m) throws Exception{
		String jsdm = f.getString("jsdm");
		f.add("obj", qxManageService.doLoad(jsdm));
		return m.findPage("/xadmin/system/setRoleWindow");
	}
	
	@RequestMapping("/updateRoleState")
	public Page doUpdateState(Form f, Module m) throws Exception {
		String jsdm = f.getString("jsdm");
		int result = f.getInt("result");
		return m.getWritePage(f, qxManageService.doUpdateState(jsdm,"zt="+result));
	}
	
}
